package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsTopicMapper;
import com.qf.pojo.DtsCoupon;
import com.qf.pojo.DtsTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

@Service
public class TopicServiceImpl implements TopicService{
    @Autowired
    private DtsTopicMapper dtsTopicMapper;

    @Override
    public IPage<DtsTopic> selectPage(int page, int limit, String sort, String order, String title, String subtitle) {
        QueryWrapper<DtsTopic> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(title),"title",title);
        queryWrapper.like(!StringUtils.isEmpty(subtitle),"subtitle",subtitle);
        queryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort);

        return dtsTopicMapper.selectPage(new Page<DtsTopic>(page,limit),queryWrapper);
    }

    @Override
    public void creattopic(DtsTopic topic) {
        topic.setAddTime(new Date());
        dtsTopicMapper.insert(topic);
    }
    @Override
    public void updatetopic(DtsTopic topic) {
        topic.setAddTime(new Date());
        topic.setUpdateTime(new Date());
        //QueryWrapper<DtsTopic> queryWrapper=new QueryWrapper<DtsTopic>().eq("title",topic.getTitle());
        dtsTopicMapper.updateById(topic);
    }
    @Override
    public void deletetopic(DtsTopic topic) {
        dtsTopicMapper.deleteById(topic);
    }
}
